package org.beian.fmmall.controller;


import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.beian.fmmall.VO.ResStatus;
import org.beian.fmmall.VO.ResultVO;
import org.beian.fmmall.beans.Users;
import org.beian.fmmall.service.UserService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/user")
@Api(tags = "用户管理",value = "用户登录注册的接口")
@CrossOrigin
public class UserController {
    @Resource
    public UserService userService;
    @ApiOperation("用户登录接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name",value = "登录账号",required = true),
            @ApiImplicitParam(name = "pwd",value = "登录密码",required = true)
    })
    @GetMapping("/login")
    public ResultVO login(String name,String pwd,HttpServletRequest request){
        ResultVO resultVO = userService.checkLogin(name, pwd);
        return resultVO;
    }
    @ApiOperation("用户注册接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name",value = "注册账号",required = true),
            @ApiImplicitParam(name = "pwd",value = "注册密码",required = true)
    })
    @PostMapping("/regist")
    public ResultVO regist(@RequestBody Users user){
        return userService.userRegist(user.getUsername(),user.getPassword());
    }
    @ApiOperation("验证token是否过期接口")
    @GetMapping("/checkTokenTimeOut")
    public ResultVO checkTokenTimeOut(@RequestHeader("token") String token){
        //只需要把这个接口添加到拦截器中
        return new ResultVO(ResStatus.OK,"success",null);
    }
}
